package com.example.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.config.ResponseVO;
import com.example.pojo.Classes;
import com.example.pojo.TeacherInfo;
import com.example.service.ClassesService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/classes")
public class ClassesController {
    @Resource
    private ClassesService classesService;

    //查全部
    @GetMapping("/classesInfoList")
    public ResponseEntity<ResponseVO<List<Classes>>> getClasses(){
        List<Classes> allClasses = classesService.getAllClasses();
        if (!allClasses.isEmpty()){
    return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"用户信息获取成功",allClasses));
        }
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"暂无用户数据",null));
    }

    //分页查询
   @GetMapping("/classesInfoListPage/{currentPage}/{limit}")
    public ResponseEntity<ResponseVO<IPage<Classes>>> getClassesPage(@PathVariable int currentPage,@PathVariable int limit){
        IPage<Classes> classesPage=classesService.getClassesPage(currentPage,limit);
       return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK, "用户信息获取成功", classesPage));
   }

   //根据年级查询出可分配的班级，并且班级人数不能大于班级最大人数
   @GetMapping("/classesInfoListDistribute/{gradeLevel}")
   public ResponseEntity<ResponseVO<List<Classes>>> classesInfoListDistribute(@PathVariable int gradeLevel){
       return classesService.classesInfoListDistribute(gradeLevel);
   }

   @GetMapping("/getClassInfoById/{classId}")
   public ResponseEntity<ResponseVO<Classes>> getClassInfoById(@PathVariable Long classId){
       Classes classInfoById = classesService.getClassInfoById(classId);
       System.out.println(Objects.isNull(classInfoById));
       if (!Objects.isNull(classInfoById)){
           return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"班级信息获取成功",classInfoById));
       }
       return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"暂无班级数据",null));
   }

    @PostMapping("/addOrUpdateClasses")
    public ResponseVO<String> addClasses(@RequestBody Classes classes) {
        String result = classesService.addOrUpdateClasses(classes);
        return ResponseVO.success(result);
    }

    @DeleteMapping("/deleteClasses/{classesId}")
    public ResponseVO<String> deleteClasses(@PathVariable Long classesId){
        String result =classesService.deleteClasses(classesId);
        return ResponseVO.success(result);
    }

    // 获取该班级的班主任或副班主任的数据
    @PostMapping("/getTeacherByClassesId/{classId}")
    public ResponseEntity<ResponseVO<List<Long>>> getTeacherByClassesId(@PathVariable Long classId) {
        return classesService.getTeacherByClassesId(classId);
    }
}
